const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageSize: 7,
    pageNumber: 1,
    orders:[]
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadOrder()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let pageNumber = this.data.pageNumber
    pageNumber = pageNumber + 1
    this.setData({
      pageNumber: pageNumber
    });
    this.loadOrder()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '琼崖租车',
      path: '/pages/index/index'
    }
  },
  loadOrder: function () {
    let that = this
    wx.request({
      url: 'https://small.qiongyazuche.com/sunday/small/order/select',
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      data: {
        'serviceId': app.globalData.userInfo.id,
        'pageNumber': that.data.pageNumber,
        'pageSize': that.data.pageSize,
        'orderStatuses':[4,5]
      },
      success: function (res) {
        let orders = that.data.orders.concat(res.data.result)
        that.setData({
          orders: orders
        });
      }
    })
  }
})